# -*- coding:utf-8 -*-
# @Time : 21-11-5 上午2:46 
# @Author : zdy
# @File : UIModifyPsw.py
# desc:
from UI.AddUser import Ui_AddUser
from importQT import *
from Class.Devices import *
from Class.UserInfo import *

class UIAddUser(QDialog, Ui_AddUser):
    def __init__(self, parent = None):
        super(UIAddUser, self).__init__(parent= parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setFixedSize(self.width(), self.height())
        self.applyResource()
        self.btnSave.clicked.connect(self.btnSave_clicked)
        self.btnCancel.clicked.connect(self.btnCancel_clicked)
        self.user = UserInfo()

    def applyResource(self):
        self.setWindowIcon(getIcon())

    def btnSave_clicked(self):
        """判断当前密码是否正确，若正确则更新新密码，关闭窗口"""
        name = self.txtUser.text()
        if currentUsers.get(name) is not None:
            QMessageBox.information(self, "提示", "用户名冲突")
        else:
            self.user.name = name
            self.user.psw = self.txtPswNew.text()
            self.accept()
            self.close()

    def btnCancel_clicked(self):
        self.close()